﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class mystudy_kecheng_play_temp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       

            Session["sid"] = Request.QueryString["rid"];    //取得当前课程的id值。
            //以下函数，取得其他相关kecheng_play.aspx需要的公共session变量：
            //①课程代码：Session[“sid”]
            //②课程对应的论坛序号（topic）Session[“stopic”]
            //③课程所属机构jigou Session[“skechengjigou”]
            //④任课老师laoshi Session[“slaoshi”]  这里是用户名，不是姓名。
            //⑤任课老师姓名：Session[“slaoshiusername1”]-->从account处取得
            //⑥课程名称Session[“skechengname”]
            //⑦课程简介Session[“skechengjianjie”]
            //⑧老师简介Session[“slaoshijianjie”]
            // ⑨学员已阅读过的章节Session["schapter"]
            //⑩课程的审核标志Session["sconfirm"],
            //默认值是“新建”，此外还有5个状态：
            //提交、审核通过、审核未通过、终审通过、终审未通过
            //只有终审通过的课程才能被学生看到并报名选修。

            //这10个变量在kecheng_play.aspx关闭时必须取消，避免占用资源。


            //以下读取account中的几个值，生成session变量。
            //strProvider = System.Configuration.ConfigurationManager.AppSettings["gConnectionString"];
            string id = Session["sid"].ToString();
            SqlConnection MyConnection = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["gConnectionString"]);
            string zsql = "select topic,jigou,laoshi,name,jianjie,confirm from kecheng where id=" + Session["sid"].ToString();
            SqlCommand myCommand = new SqlCommand(zsql, MyConnection);
            MyConnection.Open();

            SqlDataReader Reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            Reader.Read();
            Session["stopic"] = Reader.GetValue(0).ToString();
            Session["skechengjigou"] = Reader.GetValue(1).ToString();
            Session["slaoshi"] = Reader.GetValue(2).ToString();
            Session["skechengname"] = Reader.GetValue(3).ToString();
            Session["skechengjianjie"] = Reader.GetValue(4).ToString();
            Session["sconfirm"] = Reader.GetValue(5).ToString();
            Reader.Close();
            myCommand.Dispose();
            MyConnection.Close();

            //以下取得老师姓名

            //-------------------------------------------------------------
            //string sql = "select username1,grjj from account where username='" + Session["slaoshi"].ToString()+"'";
            //string zlaoshiname = conn.sqlTwo(sql);
            //if (zlaoshiname != "0")
            //{
            //    int zposi=zlaoshiname.IndexOf("|");
            //    Session["slaoshiusername1"] = zlaoshiname.Substring(0,zposi);
            //    Session["slaoshijianjie"] = zlaoshiname.Substring(zposi+1);
            //}
            //else
            //{
            //    Session["slaoshiusername1"] = "远程教育平台";
            //    Session["slaoshijianjie"] = "远程教育平台";
            //}
            //-------------------------------------------------------------
            Conn conn = new Conn();
            SqlConnection MyConnection2 = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["gConnectionString"]);
            string sql = "select username1,grjj,role,mail from account where username='" + Session["slaoshi"].ToString() + "'";
            SqlCommand myCommand2 = new SqlCommand(sql, MyConnection2);
            MyConnection2.Open();
            SqlDataReader Reader2 = myCommand2.ExecuteReader(CommandBehavior.CloseConnection);
            if (Reader2.Read())
            {
                Session["slaoshiusername1"] = Reader2.GetValue(0).ToString();
                Session["slaoshijianjie"] = Reader2.GetValue(1).ToString();
                Session["dep"] = Reader2.GetValue(2).ToString();
                Session["email"] = Reader2.GetValue(3).ToString();
                Session["dutyname"] = Reader2.GetValue(2).ToString();
            }
            else
            {
                Session["slaoshiusername1"] = "远程教育平台";
                Session["slaoshijianjie"] = "远程教育平台";
                Session["dep"] = "远程教育平台";
                Session["email"] = "远程教育平台";
                Session["dutyname"] = "远程教育平台";
            }
            Reader2.Close();
            myCommand2.Dispose();
            MyConnection.Close();
            //-------------------------------------------------------------

            Session["username1"] = Session["slaoshiusername1"].ToString();
            Session["subbbs"] = "目录";
            Session["subbbsid"] = "0";
            Session["username"] = Session["slaoshi"].ToString();
            string id1 = id;
            string name = Session["sUsername"].ToString();
           
            
            sql = string.Format("select chap from stud_chap where username='{0}' and kecheng_id='{1}'", name, id1);
            string zchap = conn.sqlFirst(sql);
            if (zchap != "0")
            {
                Session["schapter"] = zchap.Trim();
            }
            else
            {
                Session["schapter"] = "";
            }
            conn.Dispose();
            if ((Session["sRole"].ToString() == "机构") | (Session["sRole"].ToString() == "管理员"))
                Session["dutyno"] = "99";
            else if (Session["sRole"].ToString() == "教师")
                Session["dutyno"] = "5";
            else
                Session["dutyno"] = "1";

            Response.Redirect("kecheng_play.aspx");
       
    }
}
